use warnings;
use Test::More tests => '52';
use Inline C;

is(tx_init_t(), 0, 'initialize tx.');
is(handle_tx16_t('hi, this is 16000', 1, 1), 0, '16000 greets us.');
is(get_frame_16_t(1), 'hi, this is 16000', 'get the just transmitted frame.');
is(handle_tx64_t('hi, this is 64000', 1, 1), 0, '64000 greets us.');
is(get_frame_64_t(1), 'hi, this is 64000', 'get the just transmitted frame.');
is(handle_tx64_t('hi, this is 64001', 1, 1), 0, '64001 greets us.');
is(get_frame_64_t(1), 'hi, this is 64001', 'get the just transmitted frame.');
is(handle_tx64_t('hi, this is 64002', 1, 1), 0, '64002 greets us.');
is(get_frame_64_t(1), 'hi, this is 64002', 'get the just transmitted frame.');
is(handle_tx64_t('hi, this is 64003', 1, 1), 0, '64003 greets us.');
is(get_frame_64_t(1), 'hi, this is 64003', 'get the just transmitted frame.');
is(handle_tx64_t('hi, this is 64004', 1, 1), 0, '64004 greets us.');
is(get_frame_64_t(1), 'hi, this is 64004', 'get the just transmitted frame.');
is(handle_tx64_t('hi, this is 64005', 1, 1), 0, '64005 greets us.');
+is(get_frame_64_t(1), 'hi, this is 64005', 'get the just transmitted frame.');
is(handle_tx64_t('hi, this is 64006', 1, 1), 0, '64006 greets us.');
+is(get_frame_64_t(1), 'hi, this is 64006', 'get the just transmitted frame.');
is(handle_tx64_t('hi, this is 64007', 1, 1), 0, '64007 greets us.');
is(get_frame_64_t(1), 'hi, this is 64007', 'get the just transmitted frame.');
is(handle_tx64_t('hi, this is 64008', 1, 1), 0, '64008 greets us.');
is(get_frame_64_t(1), 'hi, this is 64008', 'get the just transmitted frame.');

is(tx_init_t(), 0, 'release all of the space of mac_indir and mac_retry.');

is(handle_tx16_t('hi, this is 16000', 1, 0), 0, 'after purged, we could transmit frame again.');
is(get_frame_16_t(0), 'hi, this is 16000', 'get the just transmitted frame.');
is(handle_tx16_t('hi, this is 16001', 1, 0), 0, '16001 greets us.');
is(handle_tx16_t('hi, this is 16002', 1, 0), 0, '16002 greets us.');
is(handle_tx16_t('hi, this is 16003', 1, 0), 0, '16003 greets us.');
is(handle_tx16_t('hi, this is 16004', 1, 0), 0, '16004 greets us.');
is(handle_tx16_t('hi, this is 16005', 0, 1), 0, '16005 greets us.');
is(handle_tx16_t('hi, this is 16006', 0, 1), 0, '16006 greets us.');
is(handle_tx16_t('hi, this is 16007', 0, 1), 0, '16007 greets us.');
is(handle_tx16_t('hi, this is 16008', 0, 1), 0, '16008 greets us.');
is(handle_tx16_t('hi, this is 16009', 0, 1), 0, '16009 greets us.');
is(get_frame_16_t(1), 'hi, this is 16009', 'get just transmitted frame 16009');

print "# although we have already transmitted 10 frames, but we could continue to transmit,";
print " as both the mac_indir and mac_retry is not full.\n";
is(handle_tx64_t('hi, this is 64000', 1, 0), 0, '64000 greets us');
is(handle_tx64_t('hi, this is 64001', 1, 0), 0, '64001 greets us');
is(handle_tx64_t('hi, this is 64002', 1, 0), 0, '64002 greets us');
is(handle_tx64_t('hi, this is 64003', 1, 0), 0, '64003 greets us');
is(handle_tx64_t('hi, this is 64004', 1, 0), 0, '64004 greets us');
is(get_frame_64_t(0), 'hi, this is 64004', 'get just transmitted frame 64004');

print "# though we could still send with ack set.\n";
is(handle_tx64_t('hi, this is 64005', 0, 1), 0, '64005 greets us');
is(handle_tx64_t('hi, this is 64006', 0, 1), 0, '64006 greets us');
is(handle_tx64_t('hi, this is 64007', 0, 1), 0, '64007 greets us');
is(handle_tx64_t('hi, this is 64008', 0, 1), 0, '64008 greets us');
is(handle_tx64_t('hi, this is 64009', 0, 1), 0, '64009 greets us');

is(handle_tx64_t('hi, this is 64100', 0, 0), 0, '64100 greets us');
is(handle_tx64_t('hi, this is 64101', 0, 0), 0, '64101 greets us');
is(handle_tx64_t('hi, this is 64102', 0, 0), 0, '64102 greets us');
is(handle_tx64_t('hi, this is 64103', 0, 0), 0, '64103 greets us');
is(handle_tx64_t('hi, this is 64104', 0, 0), 0, '64104 greets us');
is(handle_tx64_t('hi, this is 64105', 0, 0), 0, '64105 greets us');
is(get_frame_64_t(0), 'hi, this is 64105', 'get just transmitted frame 64105');

print "# cool!\n";

__END__
__C__

#include "../../../../mac/list.c"
#include "../../../../mac/mem.c"
#include "../../../../mac/buf.c"
#include "../../../../mac/mac_indir.c"
#include "../../../../mac/mac_retry.c"
#include "../../../../mac/mac_info.c"
#include "../../../../mac/mac_tx.c"
#include "../../../../mac/mac_phy.c"
#include "../../../../mac/mac_gen.c"
#include "../../stub/timer_stub.c"
#include "../../stub/mac_rf_stub.c"
#include "mac_tx_test.c"

int tx_init_t()
{
    return tx_init();
}

int handle_tx16_t(unsigned char *str, unsigned char retry, unsigned indir)
{
    return handle_tx16(str, retry, indir);
}

int handle_tx64_t(unsigned char *str, unsigned char retry, unsigned indir)
{
    return handle_tx64(str, retry, indir);
}

char *get_frame_16_t(unsigned char indir)
{
    MAC_DEBUG("get_frame_16_t: in it.\n");
    return get_frame_16(indir);
}

char *get_frame_64_t(unsigned char indir)
{
    return get_frame_64(indir);
}


